import http from "../common/http.js"
import store from '../store/index.js'
//获取购物车所有商品
var getCartList = async (data, needLoading) => {
	const res = await http.POST('/cart/list', data, needLoading)
	if(res.code === 0 && res.data.list) {
		store.commit('setCartNum', res.data)
	}
	return res
}
//删除购物车所有商品
var deleteCart = async (data, needLoading) => {
	const res = await http.GET('/cart/delete', data, needLoading)
	getCartList()
	return res
}
//订单提交页面
var submitPreview = (data, needLoading) => {
	return http.GET('/order/submit-preview', data, needLoading)
}
//修改购物车数量
var updateNum = async (data, needLoading) => {
	const res = await http.GET('/cart/update-num', data, needLoading)
	getCartList()
	return res
}

var scanAddCart = (data, needLoading) => {
	return http.POSTJSON('/cart/scan-add-cart', data, needLoading)
}

export default {
	getCartList,
	deleteCart,
	submitPreview,
	updateNum,
	scanAddCart
}
